package day03;

import java.util.*;

/*
 *文件名: CollectionsDemo
 *创建者:
 *创建时间:2025/5/21 09:42
 *描述:
 */
public class CollectionsDemo {
    public static void main(String[] args) {
        //test0();
        test1();
    }

    public static void test0() {
        //ArrayList<String> list = new ArrayList<>();
        List<String> list = new LinkedList<>(); //多态

        Collections.addAll(list, "A", "B", "C", "D", "E", "F");
        list.forEach(System.out::println);

        System.out.println("<---------->");

        //打乱集合顺序
        Collections.shuffle(list);
        list.forEach(System.out::println);
    }

    public static void test1(){
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 2,5,4,8,7,3,1,6,10,9);
        list.forEach(System.out::println);
        System.out.println("<---------->");
        //按倒序排序
        Collections.sort(list);
        list.forEach(System.out::println);

        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });//倒序
        System.out.println("<------------------->");
        list.forEach(System.out::println);

        System.out.println("<------------------->");
        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三",18));
        list1.add(new Student("李四",28));
        list1.add(new Student("王五",16));
        list1.add(new Student("赵六",25));
        Collections.sort(list1);
        list1.forEach(System.out::println);


    }
}
